﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer;

namespace BusinessLogicLayer
{
    public class ThamSoBLL
    {
        QuanLyChamCongDataContext DB = new QuanLyChamCongDataContext();
        public List<THAMSO> LayTatCa()
        {
            return DB.THAMSOs.ToList();
        }
        public THAMSO LayThamSo(string ma)
        {
            THAMSO n = DB.THAMSOs.SingleOrDefault(a => a.MaThamSo == ma);
            return n;
        }

        public bool KiemTraTonTai(string ma)
        {
            if (DB.THAMSOs.Any(a => a.MaThamSo == ma))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public string LayGiaTri(string ma)
        {
            THAMSO TS = DB.THAMSOs.Single(a => a.MaThamSo == ma);
            return TS.GiaTri;
        }

        public void SuaThamSo(THAMSO ts)
        {
            THAMSO Tso = DB.THAMSOs.Single(a => a.MaThamSo == ts.MaThamSo);
            Tso.GiaTri = ts.GiaTri;
            DB.SubmitChanges();
        }

        public void ThemThamSo(THAMSO ts)
        {
            DB.THAMSOs.InsertOnSubmit(ts);
            DB.SubmitChanges();
        }

        public void XoaThamSo(string ma)
        {
            THAMSO TS = DB.THAMSOs.Single(a => a.MaThamSo == ma);
            DB.THAMSOs.DeleteOnSubmit(TS);
            DB.SubmitChanges();
        }
    }
}
